package Package.Example.BypassTheGenericCheck;


import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;

public class BypassTheGenericCheck {
    public static final void BypassTheGenericCheck() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
//        通过反射技术，向一个泛型为Integer的集合中添加一些字符串数据
        ArrayList<Integer> array = new ArrayList<Integer>();

        Class<? extends ArrayList> c=array.getClass();
        Method add = c.getMethod("add", Object.class);
        add.invoke(array,"World");
        add.invoke(array,"world");
        add.invoke(array,"java");
        System.out.println(array);
    }
}
